package org.yellow.backend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yellow.backend.mapper.blacklistMapper;
import org.yellow.backend.pojo.blacklist;
import org.yellow.backend.pojo.patient;

import java.util.Date;
import java.util.List;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@Service
@SuppressWarnings({"all"})
public class blacklistService {
    @Autowired
    blacklistMapper mapper;

    /**
     * 确认患者是否在黑名单
     * @param name
     * @return
     */
    public boolean confirmedBlacklist(String name){
        QueryWrapper<blacklist> w = new QueryWrapper<>();
        w.select("violation_count").eq("name",name);
        List<blacklist> list = mapper.selectList(w);
        Long cnt = list.get(0).getViolationCount();
        if(cnt>=3){
            return false;
        }
        return true;
    }

    /**
     * 添加新患者至黑名单
     * @param patient
     * @return
     */

    public boolean insertNew(patient patient){
        System.out.println(patient);
        blacklist bl = new blacklist(null, patient.getName(), 10L, new Date());
        mapper.insert(bl);
        return true;
    }
}
